Custom indicators can be used from a strategy just like any other standard JForex platform indicator. In order to use these custom indicators in calculations they must be registered first. There are two ways how one can register a custom indicator within a strategy:<br/><ul><li>register the indicator from a compiled .jfx file;</li><li>register the indicator from a class which is located within the strategy's java file.</li></ul>For the former apporach one can also elect to package the indicators in the compiled strategy file, see below the first example for this. As an example of application of both approaches see <i>onStart</i> method of <a href="#Use_custom_indicator_in_strategies">Simple custom indicator</a>.<br/><div class="dw_article_headers_list"><div class="dw_article_header_h1"><a href="#Use_custom_indicator_in_strategies/Examples"> Examples </a></div><div class="dw_article_header_h2"><a href="#Use_custom_indicator_in_strategies/Package_custom_indicator_in_strategy_jfx_file">Package custom indicator in strategy jfx file</a></div><div class="dw_article_header_h2"><a href="#Use_custom_indicator_in_strategies/Simple_custom_indicator"> Simple custom indicator </a></div><div class="dw_article_header_h2"><a href="#Use_custom_indicator_in_strategies/Handle_multiple_outputs_and_plot_on_chart">Handle multiple outputs and plot on chart</a></div><div class="dw_article_header_h2"><a href="#Use_custom_indicator_in_strategies/Trade_with_TradersDynamicIndex">Trade with TradersDynamicIndex</a></div></div><span id="Use_custom_indicator_in_strategies/Examples"><h1> Examples </h1></span>The following examples demonstrate ways how one can register custom indicators, handle their outputs and plot them on chart.<br/><span id="Use_custom_indicator_in_strategies/Package_custom_indicator_in_strategy_jfx_file"><h2>Package custom indicator in strategy jfx file</h2></span>In order to package the indicators inside the compiled strategy one has to use the <a href="http://www.dukascopy.com/client/javadoc/com/dukascopy/api/CustomIndicators.html">CustomIndicators</a> annotation. This approach allows the user to run the strategy on other workstations without having to copy along the indicator jfx https://www.dukascopy.com/wiki/files/.<br/><b>Note:</b> <i>CustomIndicators</i> available with JForex-API 2.7.9.5. <i>IIndicators.getIndicatorByPath</i> available with JForex-API 2.9.1.<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">jforex.lib</span><span style="color: #339933;">;</span><br /><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Arrays</span><span style="color: #339933;">;</span><br /><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.*</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">static</span> com.<span style="color: #006633;">dukascopy</span>.<span style="color: #006633;">api</span>.<span style="color: #006633;">IIndicators</span>.<span style="color: #006633;">AppliedPrice</span>.<span style="color: #339933;">*;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.IIndicators.AppliedPrice</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.feed.IFeedDescriptor</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.feed.util.TimePeriodAggregationFeedDescriptor</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.indicators.IIndicator</span><span style="color: #339933;">;</span><br /><br /><span style="color: #666666; font-style: italic;">//pass file name if the indicator is located in context.getFilesDir, otherwise - full file path</span><br />@CustomIndicators<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Indicator.jfx&quot;</span><span style="color: #009900;">&#41;</span><br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CutomIndicatorPackageInJfx <span style="color: #000000; font-weight: bold;">implements</span> IStrategy <span style="color: #009900;">&#123;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IConsole console<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IIndicators indicators<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IHistory history<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span>IContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; console <span style="color: #339933;">=</span> context.<span style="color: #006633;">getConsole</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; indicators <span style="color: #339933;">=</span> context.<span style="color: #006633;">getIndicators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; history <span style="color: #339933;">=</span> context.<span style="color: #006633;">getHistory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> indPath <span style="color: #339933;">=</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAnnotation</span><span style="color: #009900;">&#40;</span>CustomIndicators.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">value</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//for multiple indicators split the path with File.pathSeparator </span><br />&nbsp; &nbsp; &nbsp; &nbsp; IIndicator indicator <span style="color: #339933;">=</span> indicators.<span style="color: #006633;">getIndicatorByPath</span><span style="color: #009900;">&#40;</span>indPath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>indicator <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #006633;">getErr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Indicator by path &quot;</span><span style="color: #339933;">+</span>indPath<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; not registered!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> indName <span style="color: #339933;">=</span> indicator.<span style="color: #006633;">getIndicatorInfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//add indicator to the last active chart if there is one</span><br />&nbsp; &nbsp; &nbsp; &nbsp; IChart chart <span style="color: #339933;">=</span> context.<span style="color: #006633;">getLastActiveChart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>chart <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>indicator<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//take feed from chart if there is one</span><br />&nbsp; &nbsp; &nbsp; &nbsp; IFeedDescriptor feedDescriptor <span style="color: #339933;">=</span> chart<span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">?</span> chart.<span style="color: #006633;">getFeedDescriptor</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">new</span> TimePeriodAggregationFeedDescriptor<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURUSD</span>, Period.<span style="color: #006633;">TEN_SECS</span>, OfferSide.<span style="color: #006633;">BID</span>, Filter.<span style="color: #006633;">NO_FILTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//use default value - just like the chart does</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> timePeriod <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span> indicator.<span style="color: #006633;">getOptInputParameterInfo</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDescription</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getOptInputDefaultValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//calculate with shift 1</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resultByShift <span style="color: #339933;">=</span> &nbsp;indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; feedDescriptor, <span style="color: #000000; font-weight: bold;">new</span> &nbsp;OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>OfferSide.<span style="color: #006633;">BID</span><span style="color: #009900;">&#125;</span>, indName, <span style="color: #000000; font-weight: bold;">new</span> AppliedPrice<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>CLOSE<span style="color: #009900;">&#125;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>timePeriod<span style="color: #009900;">&#125;</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> prevValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Double</span><span style="color: #009900;">&#41;</span> resultByShift<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">//calculate last 5</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> lastTime <span style="color: #339933;">=</span> history.<span style="color: #006633;">getFeedData</span><span style="color: #009900;">&#40;</span>feedDescriptor, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resultByCandleInterval <span style="color: #339933;">=</span> &nbsp;indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; feedDescriptor, <span style="color: #000000; font-weight: bold;">new</span> &nbsp;OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>OfferSide.<span style="color: #006633;">BID</span><span style="color: #009900;">&#125;</span>, indName, <span style="color: #000000; font-weight: bold;">new</span> AppliedPrice<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>CLOSE<span style="color: #009900;">&#125;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>timePeriod<span style="color: #009900;">&#125;</span>, <span style="color: #cc66cc;">5</span>, lastTime, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> values <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> resultByCandleInterval<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;previous=%.7f last 5=%s on feed=%s&quot;</span>, prevValue, <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>values<span style="color: #009900;">&#41;</span>, feedDescriptor<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTick<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, ITick tick<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onBar<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, Period period, IBar askBar, IBar bidBar<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onMessage<span style="color: #009900;">&#40;</span>IMessage message<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccount<span style="color: #009900;">&#40;</span>IAccount account<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//CutomIndicatorPackageInJfx.java">CutomIndicatorPackageInJfx.java</a><br/><a href="https://www.dukascopy.com/wiki/files//Indicator.java">Indicator.java</a><br/><span id="Use_custom_indicator_in_strategies/Simple_custom_indicator"><h2> Simple custom indicator </h2></span>The following strategy registers two identical indicators, calculates them and prints out the result.<br/>See Indicators section for more details on <i>IIndicators.calculateIndicator</i> method.<br/><div class="dw_article_geshi_code">...<br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span>IContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">engine</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getEngine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">console</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getConsole</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">history</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getHistory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">context</span> <span style="color: #339933;">=</span> context<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">indicators</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getIndicators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">userInterface</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getUserInterface</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//register custom indicator located in ...\\JForex\\Strategies\\https://www.dukascopy.com/wiki/files/ folder</span><br />&nbsp; &nbsp; indicators.<span style="color: #006633;">registerCustomIndicator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>context.<span style="color: #006633;">getFilesDir</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">System</span>.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;file.separator&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;Indicator.jfx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//register custom indicator defined inside a strategy</span><br />&nbsp; &nbsp; indicators.<span style="color: #006633;">registerCustomIndicator</span><span style="color: #009900;">&#40;</span>Indicator.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> firstIndicatorValues <span style="color: #339933;">=</span> &nbsp;indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURUSD</span>, Period.<span style="color: #006633;">ONE_HOUR</span>, <span style="color: #000000; font-weight: bold;">new</span> &nbsp;OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>OfferSide.<span style="color: #006633;">BID</span><span style="color: #009900;">&#125;</span>, <span style="color: #0000ff;">&quot;EXAMPIND&quot;</span>, <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> AppliedPrice<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>AppliedPrice.<span style="color: #006633;">CLOSE</span><span style="color: #009900;">&#125;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; console.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first indicator value: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>firstIndicatorValues<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> secondIndicatorValues <span style="color: #339933;">=</span> &nbsp;indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURUSD</span>, Period.<span style="color: #006633;">ONE_HOUR</span>, <span style="color: #000000; font-weight: bold;">new</span> &nbsp;OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span>OfferSide.<span style="color: #006633;">BID</span><span style="color: #009900;">&#125;</span>, <span style="color: #0000ff;">&quot;INNERINDICATOR&quot;</span>, <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> AppliedPrice<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>AppliedPrice.<span style="color: #006633;">CLOSE</span><span style="color: #009900;">&#125;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; console.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;second indicator value: &quot;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>secondIndicatorValues<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><span style="color: #009900;">&#125;</span><br />...<br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> Indicator <span style="color: #000000; font-weight: bold;">implements</span> IIndicator <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IndicatorInfo indicatorInfo <span style="color: #339933;">=</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> IndicatorInfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INNERINDICATOR&quot;</span>, <span style="color: #0000ff;">&quot;Sums previous values&quot;</span>, <span style="color: #0000ff;">&quot;My indicators&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span>, <span style="color: #000066; font-weight: bold;">false</span>, <span style="color: #000066; font-weight: bold;">false</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> InputParameterInfo<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> inputParameterInfos <span style="color: #339933;">=</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> InputParameterInfo<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">new</span> InputParameterInfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Input data&quot;</span>, InputParameterInfo.<span style="color: #006633;">Type</span>.<span style="color: #006633;">DOUBLE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> OptInputParameterInfo<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> optInputParameterInfos <span style="color: #339933;">=</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> OptInputParameterInfo<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">new</span> OptInputParameterInfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Time period&quot;</span>, OptInputParameterInfo.<span style="color: #006633;">Type</span>.<span style="color: #006633;">OTHER</span>, <span style="color: #000000; font-weight: bold;">new</span> IntegerRangeDescription<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">100</span>, <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> OutputParameterInfo<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> outputParameterInfos <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> OutputParameterInfo<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">new</span> OutputParameterInfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;out&quot;</span>, OutputParameterInfo.<span style="color: #006633;">Type</span>.<span style="color: #006633;">DOUBLE</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; OutputParameterInfo.<span style="color: #006633;">DrawingStyle</span>.<span style="color: #006633;">LINE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> inputs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> timePeriod <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> outputs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span>IIndicatorContext context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> IndicatorResult calculate<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> startIndex, <span style="color: #000066; font-weight: bold;">int</span> endIndex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//calculating startIndex taking into account lookback value</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>startIndex <span style="color: #339933;">-</span> getLookback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; startIndex <span style="color: #339933;">-=</span> startIndex <span style="color: #339933;">-</span> getLookback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> i, j<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> startIndex, j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> endIndex<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span>, j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> value <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> k <span style="color: #339933;">=</span> timePeriod<span style="color: #339933;">;</span> k <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> k<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #339933;">+=</span> inputs<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">-</span> k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputs<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> IndicatorResult<span style="color: #009900;">&#40;</span>startIndex, j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> IndicatorInfo getIndicatorInfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> indicatorInfo<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> InputParameterInfo getInputParameterInfo<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&lt;=</span> inputParameterInfos.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> inputParameterInfos<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getLookback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> timePeriod<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getLookforward<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> OptInputParameterInfo getOptInputParameterInfo<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&lt;=</span> optInputParameterInfos.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> optInputParameterInfos<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> OutputParameterInfo getOutputParameterInfo<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&lt;=</span> outputParameterInfos.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> outputParameterInfos<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setInputParameter<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index, <span style="color: #003399;">Object</span> array<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; inputs<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> array<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setOptInputParameter<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index, <span style="color: #003399;">Object</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; timePeriod <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span><span style="color: #009900;">&#41;</span> value<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setOutputParameter<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> index, <span style="color: #003399;">Object</span> array<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; outputs<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> array<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//CustomIndicatorStrategy2.java">CustomIndicatorStrategy2.java</a><br/><a href="https://www.dukascopy.com/wiki/files//Indicator.java">Indicator.java</a><br/><span id="Use_custom_indicator_in_strategies/Handle_multiple_outputs_and_plot_on_chart"><h2>Handle multiple outputs and plot on chart</h2></span>Consider a strategy which works with a custom, multi-output indicator and shows how to go about:<br/><ul><li>parsing and logging custom indicator's outputs,</li><li>plotting custom indicator on the chart.</li></ul>There are two calculation variants used:<br/><ul><li>by shift (single value),</li><li>by candle interval (value array).</li></ul>Before launching the strategy, compile the <a href="https://www.dukascopy.com/wiki/files//AwesomeOscillatorCustom.java">AwesomeOscillator</a> indicator and then in parameters dialog select the compiled .jfx file's location.<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">jforex.strategies</span><span style="color: #339933;">;</span><br /><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Color</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.DecimalFormat</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.SimpleDateFormat</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.*</span><span style="color: #339933;">;</span><br /><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.*</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.IIndicators.MaType</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.indicators.IIndicator</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle</span><span style="color: #339933;">;</span><br /><br /><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />&nbsp;* The following strategy shows how one can use a custom, multi-output indicator by:<br />&nbsp;* - parsing and logging its outputs,<br />&nbsp;* - plotting it on the chart.<br />&nbsp;* <br />&nbsp;* There are two calculation variants used:<br />&nbsp;* &nbsp;- by shift (single value)<br />&nbsp;* &nbsp;- by candle interval (value array)<br />&nbsp;*<br />&nbsp;*/</span><br />@RequiresFullAccess<br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomIndicatorPlotAndLogValues2 <span style="color: #000000; font-weight: bold;">implements</span> IStrategy <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IConsole console<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IIndicators indicators<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IChart chart<span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">File</span> indicatorJfxFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:/temp/AwesomeOscillatorCustom.jfx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Instrument&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Instrument</span> instrument <span style="color: #339933;">=</span> <span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURUSD</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Period&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Period period <span style="color: #339933;">=</span> Period.<span style="color: #006633;">TEN_SECS</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Printable bar count&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> candleCount <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Shift&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> shift <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//optional inputs according to optInputParameterInfos of the indicator</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> FasterMATimePeriod <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> MaType FasterMaType <span style="color: #339933;">=</span> MaType.<span style="color: #006633;">SMA</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> SlowerMATimePeriod <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> MaType SlowerMAType <span style="color: #339933;">=</span> MaType.<span style="color: #006633;">SMA</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//outputs according to outputParameterInfos of the indicator </span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> ZeroOutput<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> PositiveOutput<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> NegativeOutput<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span> ZeroByShift<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span> PositiveByShift<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">double</span> NegativeByShift<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> outCount <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> indicatorName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;AwesomeCustom&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> optionalInputArray<span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; <span style="color: #003399;">DecimalFormat</span> df <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">DecimalFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;0.00000##&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serial&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #003399;">SimpleDateFormat</span> sdf <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dd.MM.yyyy HH:mm:ss&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setTimeZone<span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span>IContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">console</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getConsole</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">indicators</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getIndicators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">chart</span> <span style="color: #339933;">=</span> context.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span>instrument<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">indicators</span>.<span style="color: #006633;">registerCustomIndicator</span><span style="color: #009900;">&#40;</span>indicatorJfxFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//note that we retrieve int value of MaType enum</span><br />&nbsp; &nbsp; &nbsp; &nbsp; optionalInputArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> FasterMATimePeriod, FasterMaType.<span style="color: #006633;">ordinal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, SlowerMATimePeriod, SlowerMAType.<span style="color: #006633;">ordinal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; IIndicator awesomeCustom <span style="color: #339933;">=</span> indicators.<span style="color: #006633;">getIndicator</span><span style="color: #009900;">&#40;</span>indicatorName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; chart.<span style="color: #006633;">addIndicator</span><span style="color: #009900;">&#40;</span>awesomeCustom, optionalInputArray, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Color</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLACK</span>, <span style="color: #003399;">Color</span>.<span style="color: #006633;">BLUE</span>.<span style="color: #006633;">darker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #003399;">Color</span>.<span style="color: #006633;">MAGENTA</span>.<span style="color: #006633;">brighter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> DrawingStyle<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> DrawingStyle.<span style="color: #006633;">DASHDOT_LINE</span>, DrawingStyle.<span style="color: #006633;">HISTOGRAM</span> ,DrawingStyle.<span style="color: #006633;">HISTOGRAM</span> <span style="color: #009900;">&#125;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> print<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccount<span style="color: #009900;">&#40;</span>IAccount account<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onMessage<span style="color: #009900;">&#40;</span>IMessage message<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; chart.<span style="color: #006633;">removeAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTick<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, ITick tick<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onBar<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, Period period, IBar askBar, IBar bidBar<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>instrument <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">instrument</span> <span style="color: #339933;">||</span> period <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">period</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br /><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resultArr <span style="color: #339933;">=</span> indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">instrument</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">period</span>, <span style="color: #000000; font-weight: bold;">new</span> OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> OfferSide.<span style="color: #006633;">BID</span> <span style="color: #009900;">&#125;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; indicatorName, <span style="color: #000000; font-weight: bold;">new</span> IIndicators.<span style="color: #006633;">AppliedPrice</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> IIndicators.<span style="color: #006633;">AppliedPrice</span>.<span style="color: #006633;">CLOSE</span> <span style="color: #009900;">&#125;</span>, optionalInputArray,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Filter.<span style="color: #006633;">NO_FILTER</span>, candleCount, bidBar.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> resultByShift <span style="color: #339933;">=</span> indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">instrument</span>, <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">period</span>, <span style="color: #000000; font-weight: bold;">new</span> OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> OfferSide.<span style="color: #006633;">BID</span> <span style="color: #009900;">&#125;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; indicatorName, <span style="color: #000000; font-weight: bold;">new</span> IIndicators.<span style="color: #006633;">AppliedPrice</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> IIndicators.<span style="color: #006633;">AppliedPrice</span>.<span style="color: #006633;">CLOSE</span> <span style="color: #009900;">&#125;</span>, optionalInputArray,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shift<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//this array is to hold all outputs</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> outputArrays <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span>outCount<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> outputsByShift <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span>outCount<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> outCount<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputArrays<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> resultArr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputsByShift<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>resultByShift<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//for convenience assign the results to meaningful variables</span><br />&nbsp; &nbsp; &nbsp; &nbsp; ZeroOutput <span style="color: #339933;">=</span> outputArrays<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; PositiveOutput <span style="color: #339933;">=</span> outputArrays<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; NegativeOutput <span style="color: #339933;">=</span> outputArrays<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ZeroByShift <span style="color: #339933;">=</span> outputsByShift<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; PositiveByShift <span style="color: #339933;">=</span> outputsByShift<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; NegativeByShift <span style="color: #339933;">=</span> outputsByShift<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; print<span style="color: #009900;">&#40;</span>sdf.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>bidBar.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; Outputs for the last &quot;</span> <span style="color: #339933;">+</span>candleCount<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot; bars:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; print<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ZeroOutput: &quot;</span> <span style="color: #339933;">+</span> arrayToStringLast<span style="color: #009900;">&#40;</span>ZeroOutput<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; print<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PositiveOutput: &quot;</span> <span style="color: #339933;">+</span> getMaxInfo<span style="color: #009900;">&#40;</span>PositiveOutput<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> arrayToStringLast<span style="color: #009900;">&#40;</span>PositiveOutput<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; print<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;NegativeOutput: &quot;</span> <span style="color: #339933;">+</span> getMinInfo<span style="color: #009900;">&#40;</span>NegativeOutput<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> arrayToStringLast<span style="color: #009900;">&#40;</span>NegativeOutput<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; print<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Outputs by shift=%s: Zero=%s Positive=%s Negative=%s&quot;</span>,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shift, ZeroByShift, df.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>PositiveByShift<span style="color: #009900;">&#41;</span>, df.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>NegativeByShift<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> getMaxInfo<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> value <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">MIN_VALUE</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arr.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #339933;">=</span> arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Max value &quot;</span> <span style="color: #339933;">+</span> df.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; index: &quot;</span> <span style="color: #339933;">+</span> index <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; &quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> getMinInfo<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> value <span style="color: #339933;">=</span> <span style="color: #003399;">Double</span>.<span style="color: #006633;">MAX_VALUE</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arr.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #339933;">=</span> arr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Min value &quot;</span> <span style="color: #339933;">+</span> df.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; index: &quot;</span> <span style="color: #339933;">+</span> index <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; &quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> arrayToStringLast<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> arr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> str <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> r <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> r <span style="color: #339933;">&lt;</span> arr.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> r<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot; [&quot;</span> <span style="color: #339933;">+</span> r <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;]&quot;</span> <span style="color: #339933;">+</span> df.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>r<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> str<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><span style="color: #009900;">&#125;</span><br /></div><a href="https://www.dukascopy.com/wiki/files//CustomIndicatorPlotAndLogValues2.java">CustomIndicatorPlotAndLogValues2.java</a><br/><a href="https://www.dukascopy.com/wiki/files//AwesomeOscillatorCustom.java">AwesomeOscillatorCustom.java</a><br/><span id="Use_custom_indicator_in_strategies/Trade_with_TradersDynamicIndex"><h2>Trade with TradersDynamicIndex</h2></span>The strategy trades according to TradersDynamicIndex custom indicator.<br/> It makes:<br/><ul><li>a BUY order if green ("RSI Price Line") crosses above red ("Trade Signal Line")</li><li>a SELL order - if green crosses below red.</li></ul>On its start the strategy plots the indicator on the chart. The strategy works only in determined market hours. The strategy applies take profit and stop loss prices and on new order creation, it closes the previous one.<br/><div class="dw_article_geshi_code"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">jforex.strategies.requests</span><span style="color: #339933;">;</span><br /><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.*</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.IEngine.OrderCommand</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.IIndicators.AppliedPrice</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.IIndicators.MaType</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.dukascopy.api.indicators.IIndicator</span><span style="color: #339933;">;</span><br /><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.ParseException</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.text.SimpleDateFormat</span><span style="color: #339933;">;</span><br /><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.TimeZone</span><span style="color: #339933;">;</span><br /><br /><span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />&nbsp;* The strategy trades according to TradersDynamicIndex.jfx custom indicator.<br />&nbsp;* It makes:<br />&nbsp;* - a BUY order if green (&quot;RSI Price Line&quot;) crosses above red (&quot;Trade Signal Line&quot;), <br />&nbsp;* - a SELL order - if green crosses below red.<br />&nbsp;* <br />&nbsp;* On its start the strategy plots the indicator on the chart.<br />&nbsp;* <br />&nbsp;* The strategy works only in determined market hours<br />&nbsp;* <br />&nbsp;*/</span><br />@RequiresFullAccess<br /><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TradeTDI2 <span style="color: #000000; font-weight: bold;">implements</span> IStrategy <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IConsole console<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IHistory history<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IIndicators indicators<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IEngine engine<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IIndicator indicator<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IChart chart<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IOrder order<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TDI .jfx file&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">File</span> jfxFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;C:<span style="color: #000099; font-weight: bold;">\\\\</span>temp<span style="color: #000099; font-weight: bold;">\\\\</span>TradersDynamicIndex.jfx&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;from time (HH:mm)&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> fromTimeStr <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;08:00&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;to time (HH:mm)&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toTimeStr <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;15:00&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Instrument</span> instrument <span style="color: #339933;">=</span> <span style="color: #003399;">Instrument</span>.<span style="color: #006633;">EURUSD</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> Period period <span style="color: #339933;">=</span> Period.<span style="color: #006633;">FIFTEEN_MINS</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> OfferSide side <span style="color: #339933;">=</span> OfferSide.<span style="color: #006633;">BID</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> AppliedPrice appliedPrice <span style="color: #339933;">=</span> AppliedPrice.<span style="color: #006633;">CLOSE</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">double</span> orderAmount <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0.001</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SL (pips)&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> slPips <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TP (pips)&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> tpPips <span style="color: #339933;">=</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; @Configurable<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slippage (pips)&quot;</span><span style="color: #009900;">&#41;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> slippage <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> indName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;TDI&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> counter<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> optInputs<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> rsiPeriod <span style="color: #339933;">=</span> <span style="color: #cc66cc;">13</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> rsiPriceLine <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> priceMaType <span style="color: #339933;">=</span> MaType.<span style="color: #006633;">SMA</span>.<span style="color: #006633;">ordinal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> tradeSignalLine <span style="color: #339933;">=</span> <span style="color: #cc66cc;">7</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> signalMaType <span style="color: #339933;">=</span> MaType.<span style="color: #006633;">SMA</span>.<span style="color: #006633;">ordinal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> volatilityBand <span style="color: #339933;">=</span> <span style="color: #cc66cc;">34</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> volatility <span style="color: #339933;">=</span> MaType.<span style="color: #006633;">SMA</span>.<span style="color: #006633;">ordinal</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> showBGLines <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">SimpleDateFormat</span> gmtSdf <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;yyyy-MM-dd HH:mm:ss&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStart<span style="color: #009900;">&#40;</span>IContext context<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; console <span style="color: #339933;">=</span> context.<span style="color: #006633;">getConsole</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; history <span style="color: #339933;">=</span> context.<span style="color: #006633;">getHistory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; indicators <span style="color: #339933;">=</span> context.<span style="color: #006633;">getIndicators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; engine <span style="color: #339933;">=</span> context.<span style="color: #006633;">getEngine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; chart <span style="color: #339933;">=</span> context.<span style="color: #006633;">getChart</span><span style="color: #009900;">&#40;</span>instrument<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; gmtSdf.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;GMT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; indicators.<span style="color: #006633;">registerCustomIndicator</span><span style="color: #009900;">&#40;</span>jfxFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; indicator <span style="color: #339933;">=</span> context.<span style="color: #006633;">getIndicators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getIndicator</span><span style="color: #009900;">&#40;</span>indName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; optInputs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rsiPeriod, rsiPriceLine, priceMaType, tradeSignalLine, signalMaType, volatilityBand, volatility, showBGLines<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; chart.<span style="color: #006633;">addIndicator</span><span style="color: #009900;">&#40;</span>indicator, optInputs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//plot only if the chart matches the parameters that are used for indicator calculation</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>chart.<span style="color: #006633;">getSelectedPeriod</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">period</span> &nbsp;<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printErr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;For proper indicator values please change chart period to &quot;</span><span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">period</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>chart.<span style="color: #006633;">getSelectedOfferSide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">side</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printErr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;For proper indicator values please change chart side to &quot;</span><span style="color: #339933;">+</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">side</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//use of string operations</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isValidTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> lastTickTime <span style="color: #339933;">=</span> history.<span style="color: #006633;">getLastTick</span><span style="color: #009900;">&#40;</span>instrument<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//you want to work with the date of the last tick - in a case you are back-testing</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> fromStr <span style="color: #339933;">=</span> gmtSdf.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>lastTickTime<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> fromTimeStr <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:00&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">String</span> toStr <span style="color: #339933;">=</span> gmtSdf.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>lastTickTime<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> toTimeStr <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;:00&quot;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> from <span style="color: #339933;">=</span> gmtSdf.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>fromStr<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> to <span style="color: #339933;">=</span> gmtSdf.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span>toStr<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">=</span> lastTickTime <span style="color: #339933;">&gt;</span> from &nbsp;<span style="color: #339933;">&amp;&amp;</span> lastTickTime <span style="color: #339933;">&lt;</span> to<span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">ParseException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onBar<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, Period period, IBar askBar, IBar bidBar<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>period <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">period</span> <span style="color: #339933;">||</span> instrument <span style="color: #339933;">!=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">instrument</span> <span style="color: #339933;">||</span> &nbsp;<span style="color: #339933;">!</span>isValidTime<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> candlesBefore <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span>, candlesAfter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">long</span> currBarTime <span style="color: #339933;">=</span> bidBar.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003399;">Object</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> patternUni <span style="color: #339933;">=</span> indicators.<span style="color: #006633;">calculateIndicator</span><span style="color: #009900;">&#40;</span>instrument, period, <span style="color: #000000; font-weight: bold;">new</span> OfferSide<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> side <span style="color: #009900;">&#125;</span>, indName,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> AppliedPrice<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> appliedPrice <span style="color: #009900;">&#125;</span>, optInputs, Filter.<span style="color: #006633;">NO_FILTER</span>, candlesBefore, currBarTime, candlesAfter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> rsiLine <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> patternUni<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> signalLine <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> patternUni<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> last <span style="color: #339933;">=</span> rsiLine.<span style="color: #006633;">length</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; print<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;%s rsi: last - %.5f, previous - %.5f; signal: last - %.5f, previous = %.5f&quot;</span>, <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gmtSdf.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>bidBar.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>, rsiLine<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span>, rsiLine<span style="color: #009900;">&#91;</span>last<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>, signalLine<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span>, signalLine<span style="color: #009900;">&#91;</span>last<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//buy if green (&quot;RSI Price Line&quot;) crosses above red (&quot;Trade Signal Line&quot;) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rsiLine<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> signalLine<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> rsiLine<span style="color: #009900;">&#91;</span>last <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> signalLine<span style="color: #009900;">&#91;</span>last <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; submitOrder<span style="color: #009900;">&#40;</span>OrderCommand.<span style="color: #006633;">BUY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//sell at green crossing below red</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rsiLine<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> signalLine<span style="color: #009900;">&#91;</span>last<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> rsiLine<span style="color: #009900;">&#91;</span>last <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> signalLine<span style="color: #009900;">&#91;</span>last <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; submitOrder<span style="color: #009900;">&#40;</span>OrderCommand.<span style="color: #006633;">SELL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #008000; font-style: italic; font-weight: bold;">/**<br />&nbsp; &nbsp; &nbsp;* Submits an order at market price with SL and TP.<br />&nbsp; &nbsp; &nbsp;* <br />&nbsp; &nbsp; &nbsp;* @param orderCmd<br />&nbsp; &nbsp; &nbsp;* @return<br />&nbsp; &nbsp; &nbsp;* @throws JFException<br />&nbsp; &nbsp; &nbsp;*/</span><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> IOrder submitOrder<span style="color: #009900;">&#40;</span>OrderCommand orderCmd<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//send request to close the previous order</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>order <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> order.<span style="color: #006633;">getState</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> IOrder.<span style="color: #006633;">State</span>.<span style="color: #006633;">FILLED</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> bid <span style="color: #339933;">=</span> history.<span style="color: #006633;">getLastTick</span><span style="color: #009900;">&#40;</span>instrument<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> ask <span style="color: #339933;">=</span> history.<span style="color: #006633;">getLastTick</span><span style="color: #009900;">&#40;</span>instrument<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAsk</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> pip <span style="color: #339933;">=</span> instrument.<span style="color: #006633;">getPipValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//calculate SL and TP prices</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> stopLossPrice <span style="color: #339933;">=</span> orderCmd.<span style="color: #006633;">isLong</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">?</span> bid <span style="color: #339933;">-</span> slPips <span style="color: #339933;">*</span> pip <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">:</span> ask <span style="color: #339933;">+</span> slPips <span style="color: #339933;">*</span> pip<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">double</span> takeProfitPrice <span style="color: #339933;">=</span> orderCmd.<span style="color: #006633;">isLong</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">?</span> bid <span style="color: #339933;">+</span> tpPips <span style="color: #339933;">*</span> pip <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">:</span> ask <span style="color: #339933;">-</span> tpPips <span style="color: #339933;">*</span> pip<span style="color: #339933;">;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; order <span style="color: #339933;">=</span> engine.<span style="color: #006633;">submitOrder</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;order&quot;</span> <span style="color: #339933;">+</span> <span style="color: #339933;">++</span>counter , instrument, orderCmd, orderAmount, <span style="color: #cc66cc;">0</span>, slippage, stopLossPrice, takeProfitPrice<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /><br />&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> order<span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> print<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; <br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> printErr<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />&nbsp; &nbsp; &nbsp; &nbsp; console.<span style="color: #006633;">getErr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTick<span style="color: #009900;">&#40;</span><span style="color: #003399;">Instrument</span> instrument, ITick tick<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onMessage<span style="color: #009900;">&#40;</span>IMessage message<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onAccount<span style="color: #009900;">&#40;</span>IAccount account<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />&nbsp; &nbsp; @Override<br />&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JFException <span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br /><br /><span style="color: #009900;">&#125;</span></div><a href="https://www.dukascopy.com/wiki/files//TradeTDI2.java">TradeTDI2.java</a><br/><a href="https://www.dukascopy.com/wiki/files//TradersDynamicIndex.java">TradersDynamicIndex.java</a>